<?php
namespace app\api\model;


use think\Model;

class User extends Common
{
    public function register($mobile,$password)
    {
    	return $this->createOrUpdateUser(null,$mobile,$password);
    }

    public function createOrUpdateUser(?User $user,$mobile='',$password='',$email='',$nickname='',$headImg='')
    {
    	if(empty($user)){
    		$user = new self();
    		if(empty($nickname)){
    			$nickname =  '用户_'.rand(1000000,9999999);
    		}
    	}
    	$mobile && $user->mobile = $mobile;
    	$password && $user->password = md5($password);
    	$email && $user->email = $email;
    	$headImg && $user->head_img = $headImg;
    	$nickname && $user->nickname = $nickname;
    	$user->save();
    	return $user;
    }
}